package com.blog.utils;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import net.sf.json.JSONArray;

public class AlgorithmUtil {
	public static int n[] = { 1, 7, 4, 2, 8, 0, 3 };

	public static void bubbleSort(int[] n) {
		System.out.println(JSONArray.fromObject(n).toString());
		int temp;
		for (int i = -1; i < n.length; i++) {
			for (int j = n.length - 1; j > i + 1; j--) {
				if (n[j] < n[j - 1]) {
					temp = n[j];
					n[j] = n[j - 1];
					n[j - 1] = temp;
				}
				// System.out.println(JSONArray.fromObject(n).toString());
			}
		}
	}

	public static void main(String[] args) {
		System.out.println(AlgorithmUtil.randomIntArray(100).length);
		int[] is = (int[])(Object)AlgorithmUtil.randomIntArray(100);
		//AlgorithmUtil.bubbleSort(is);
		//System.out.println(JSONArray.fromObject(is));
	}

	public static Object[] randomIntArray(int length) {
		List<Integer> list = new ArrayList<Integer>();
		int[] ints = new int[length];
		Random r = new Random();
		while (list.size() < length) {
			int n = r.nextInt(100);
			System.out.println(ints.toString());
			if (!list.contains(n)) {
				list.add(n);
			}
		}
		return list.toArray();
	}

	public void s(int a) {
		a++;
	}
}